﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;

using PercolationTree.Model;
using PercolationTree.Util;

namespace PercolationTree.Experiments
{
    class TreesPerChanceExperiment : IExperiment
    {
        private int m_MaxChildrenCount = 20;
        private int m_MaxLayersCount = 4;
        public TreesPerChanceExperiment(int maxChildrenCount, int maxLayersCount)
        {
            m_MaxChildrenCount = maxChildrenCount;
            m_MaxLayersCount = maxLayersCount;
        }
        public IList<Point> process(FactoryFunction factoryFunc)
        {
            Tree tree = factoryFunc(m_MaxChildrenCount, m_MaxLayersCount);
            while (Statistics.getNodesNumber(tree) < 200)
                tree = factoryFunc(m_MaxChildrenCount, m_MaxLayersCount);

            IList<Point> results = new List<Point>();
            for (int chance = 0; chance <= 100; chance += 9)
            {
                int validTreeCount = 0;
                for (int treeCount = 0; treeCount < 100; treeCount++)
                {
                    tree.Percolate(chance / 100.0f);
                    if  (Statistics.isTreePassSignal(tree))
                        validTreeCount++;
                }
                results.Add(new Point(chance, validTreeCount));
            }
            return results;
        }
    }
}
